﻿using Microsoft.AspNetCore.Mvc;
using mozhi.smarterp.BasicData.Products;
using mozhi.smarterp.BasicData.Units;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace mozhi.smarterp.BasicData.Controllers
{
    [RemoteService]
    [Route("api/v1/products")]
    public class ProductController : BasicDataController
    {
        private IProductAppService _appService;
        private IProductAuxiliaryUnitAppService _auxiliaryUnitAppService;

        public ProductController(IProductAppService appService, IProductAuxiliaryUnitAppService auxiliaryUnitAppService)
        {
            _appService = appService;
            _auxiliaryUnitAppService = auxiliaryUnitAppService;
        }

        [HttpGet]
        public async Task<PagedResultDto<ProductListDto>> GetPageListAsync(ProductResultRequestDto filter)
        {
            return await _appService.GetListAsync(filter);
        }

        [HttpGet]
        [Route("{id}")]
        public async Task<ProductDto> GetAsync(Guid id)
        {
            return await _appService.GetAsync(id);
        }

        [HttpPost]
        public async Task<ProductDto> CreateAsync(ProductCreateDto input)
        {
            return await _appService.CreateAsync(input);
        }

        [HttpPut]
        public async Task<ProductDto> UpdateAsync(ProductUpdateDto input)
        {
            return await _appService.UpdateAsync(input);
        }

        [HttpDelete]
        [Route("{id}")]
        public async Task DeleteAsync(Guid id)
        {
            await _appService.DeleteAsync(id);

        }


        [HttpGet]
        [Route("auxiliary-units")]
        public async Task<PagedResultDto<ProductAuxiliaryUnitDto>> GetAuxiliaryUnitPageListAsync(ProductAuxiliaryUnitResultRequestDto filter)
        {
            return await _auxiliaryUnitAppService.GetListAsync(filter);
        }

        [HttpGet]
        [Route("auxiliary-units/{id}")]
        public async Task<ProductAuxiliaryUnitDto> GetAuxiliaryUnitAsync(Guid id)
        {
            return await _auxiliaryUnitAppService.GetAsync(id);
        }

        [HttpPost]
        [Route("auxiliary-units")]
        public async Task<ProductAuxiliaryUnitDto> CreateAuxiliaryUnitAsync(ProductAuxiliaryUnitCreateDto input)
        {
            return await _auxiliaryUnitAppService.CreateAsync(input);
        }

        [HttpPut]
        [Route("auxiliary-units")]
        public async Task<ProductAuxiliaryUnitDto> UpdateAuxiliaryUnitAsync(ProductAuxiliaryUnitUpdateDto input)
        {
            return await _auxiliaryUnitAppService.UpdateAsync(input);
        }

        [HttpDelete]
        [Route("auxiliary-units/{id}")]
        public async Task DeleteAuxiliaryUnitAsync(Guid id)
        {
            await _auxiliaryUnitAppService.DeleteAsync(id);

        }
    }
}
